//
//  GuiJiAnnotationView.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/11/19.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "GuiJiAnnotationView.h"

@interface GuiJiAnnotationView ()

@property (nonatomic, strong) UIImageView *iconImgView;

@end

@implementation GuiJiAnnotationView

#ifdef USE_SYSTHESIZE
@synthesize annotation = _annotation; //不会使用父类的set方法 在 setAnnotation方法里 要明确表明 _annotation = annotation;
#else
@dynamic annotation; //用@dynamic后 get 和 set 方法应该获取到的是父类类型的 annotation
#endif

- (instancetype)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        //大头针的图片
        self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(-18, -36, 36, 36)];
        [self addSubview:self.iconImgView];
    }
    return self;
}

#ifdef USE_SYSTHESIZE
#pragma mark 当给大头针视图设置大头针模型时可以在此根据模型设置视图内容 @synthesize annotation = _annotation;
-(void)setAnnotation:(LJAnnotation *)annotation{
    _annotation = annotation;
}
#else
#pragma mark 当给大头针视图设置大头针模型时可以在此根据模型设置视图内容 //@dynamic annotation;
-(void)setAnnotation:(LJAnnotation *)annotation{
    [super setAnnotation:annotation];
//    self.numLab.text = [NSString stringWithFormat:@"%ld",(long)annotation.num];
//    if (annotation.type == 1) {
        self.iconImgView.image = [UIImage imageNamed:@"icon_rise"];
//        self.numLab.backgroundColor = HexColor(0x5780D9);
//    }else {
//        self.iconImgView.image = [UIImage imageNamed:@"shou_map_ann"];
//        self.numLab.backgroundColor = HexColor(0xFBA962);
//    }
    //根据模型调整布局
//    self.iconImgView.image = annotation.image;
//    self.iconImgView.frame = CGRectMake(0, 0, 30, 30);
//    _iconView.image=annotation.icon;
//    _iconView.frame=CGRectMake(kSpacing, kSpacing, annotation.icon.size.width, annotation.icon.size.height);
////
//    _detailLabel.text=annotation.detail;
//    float detailWidth=150.0;
//    CGSize detailSize= [annotation.detail boundingRectWithSize:CGSizeMake(detailWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:kDetailFontSize]} context:nil].size;
//    float detailX=CGRectGetMaxX(_iconView.frame)+kSpacing;
//    _detailLabel.frame=CGRectMake(detailX, kSpacing, detailSize.width, detailSize.height);
//    _rateView.image=annotation.rate;
//    _rateView.frame=CGRectMake(detailX, CGRectGetMaxY(_detailLabel.frame)+kSpacing, annotation.rate.size.width, annotation.rate.size.height);
////
//    float backgroundWidth=CGRectGetMaxX(_detailLabel.frame)+kSpacing;
//    float backgroundHeight=_iconView.frame.size.height+2*kSpacing;
//    _backgroundView.frame=CGRectMake(0, 0, backgroundWidth, backgroundHeight);
//    self.bounds=CGRectMake(0, 0, 30, 30);
}
#endif


//
//
//- (instancetype)init{
//    if (self = [super init]) {
//        [self layoutUI];
//    }
//    return self;
//}
//
//- (instancetype)initWithFrame:(CGRect)frame {
//    if (self = [super initWithFrame:frame]) {
//        [self layoutUI];
//    }
//    return self;
//}
//
//- (void)layoutUI {
//    self.iconImgView = [UIImageView new];
//    [self addSubview:self.iconImgView];
//}
//
//+ (instancetype)calloutViewWithMapView:(MKMapView *)mapView {
//    static NSString *calloutKey = @"LJAnnotationView";
//    LJAnnotationView *calloutView = (LJAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:calloutKey];
//    if (!calloutView) {
//        calloutView = [[LJAnnotationView alloc]init];
//    }
//    return calloutView;
//}
//
//+ (instancetype)initCalloutViewWithMapView:(MKMapView *)mapView setKCCalloutAnnotation:(LJAnnotation *)ljAnnotation {
//    static NSString *calloutKey = @"LJAnnotationView";
//    LJAnnotationView *calloutView = (LJAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:calloutKey];
//    if (!calloutView) {
//        calloutView = [[LJAnnotationView alloc] initWithAnnotation:ljAnnotation reuseIdentifier:calloutKey];
//    }
//    return calloutView;
//}
//
//
//#ifdef USE_SYSTHESIZE
//#pragma mark 当给大头针视图设置大头针模型时可以在此根据模型设置视图内容 @synthesize annotation = _annotation;
//-(void)setAnnotation:(LJAnnotation *)annotation{
//    _annotation = annotation;
////    //    //根据模型调整布局
////    _iconView.image=annotation.icon;
////    _iconView.frame=CGRectMake(kSpacing, kSpacing, annotation.icon.size.width, annotation.icon.size.height);
////    //
////    _detailLabel.text=annotation.detail;
////    float detailWidth=150.0;
////    CGSize detailSize= [annotation.detail boundingRectWithSize:CGSizeMake(detailWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:kDetailFontSize]} context:nil].size;
////    float detailX=CGRectGetMaxX(_iconView.frame)+kSpacing;
////    _detailLabel.frame=CGRectMake(detailX, kSpacing, detailSize.width, detailSize.height);
////    _rateView.image=annotation.rate;
////    _rateView.frame=CGRectMake(detailX, CGRectGetMaxY(_detailLabel.frame)+kSpacing, annotation.rate.size.width, annotation.rate.size.height);
////    //
////    float backgroundWidth=CGRectGetMaxX(_detailLabel.frame)+kSpacing;
////    float backgroundHeight=_iconView.frame.size.height+2*kSpacing;
////    _backgroundView.frame=CGRectMake(0, 0, backgroundWidth, backgroundHeight);
////    self.bounds=CGRectMake(0, 0, backgroundWidth, backgroundHeight+kViewOffset);
//}
//#else
//#pragma mark 当给大头针视图设置大头针模型时可以在此根据模型设置视图内容 //@dynamic annotation;
//-(void)setAnnotation:(LJAnnotation *)annotation{
//    [super setAnnotation:annotation];
//    //根据模型调整布局
//    self.iconImgView.image = annotation.image;
//    self.iconImgView.frame = CGRectMake(0, 0, 30, 30);
////    _iconView.image=annotation.icon;
////    _iconView.frame=CGRectMake(kSpacing, kSpacing, annotation.icon.size.width, annotation.icon.size.height);
//////
////    _detailLabel.text=annotation.detail;
////    float detailWidth=150.0;
////    CGSize detailSize= [annotation.detail boundingRectWithSize:CGSizeMake(detailWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:kDetailFontSize]} context:nil].size;
////    float detailX=CGRectGetMaxX(_iconView.frame)+kSpacing;
////    _detailLabel.frame=CGRectMake(detailX, kSpacing, detailSize.width, detailSize.height);
////    _rateView.image=annotation.rate;
////    _rateView.frame=CGRectMake(detailX, CGRectGetMaxY(_detailLabel.frame)+kSpacing, annotation.rate.size.width, annotation.rate.size.height);
//////
////    float backgroundWidth=CGRectGetMaxX(_detailLabel.frame)+kSpacing;
////    float backgroundHeight=_iconView.frame.size.height+2*kSpacing;
////    _backgroundView.frame=CGRectMake(0, 0, backgroundWidth, backgroundHeight);
//    self.bounds=CGRectMake(0, 0, 30, 30);
//}
//#endif

@end
